package main

import (
	"bluebell/controller"
	"bluebell/dao/mysql"
	"bluebell/dao/redis"
	"bluebell/logger"
	"bluebell/pkg/snowflake"
	"bluebell/routers"
	"bluebell/settings"
	"fmt"
)

// @title          api 文档
// @version        1.0
// @description    这是一个博格论坛
// @termsOfService http://swagger.io/terms/

// @contact.name  API Support
// @contact.url   http://www.swagger.io/support
// @contact.email support@swagger.io

// @license.name Apache 2.0
// @license.url  http://www.apache.org/licenses/LICENSE-2.0.html
// @host         127.0.0.1:8080
// @BasePath

// @securityDefinitions.basic BasicAuth
func main(){
	//获取配置文件
	appconfig := settings.Get()
	//初始化zaplogger
	logger.InitZapLog(appconfig.LogConfig,appconfig.Mode)
	//初始化mysql
	mysql.InitGorm(appconfig.MySQLConfig)
	defer mysql.Close() // 程序退出关闭数据库连接
	//初始化redis
	redis.InitRedis(appconfig.RedisConfig)
	defer redis.Close()
	//雪花算法生成分布式ID ---> 机器ID为 1
	snowflake.Init(1)
	//gin的validator ---> 中文翻译器
	err := controller.InitTrans("zh")
	if err != nil {
		fmt.Printf("init validator Trans failed,err:%v\n", err)
		return
	}

	// 注册路由
	r := routers.SetupRouter(appconfig.Mode)
	err = r.Run(fmt.Sprintf(":%d", appconfig.Port))
	if err != nil {
		fmt.Printf("run server failed, err:%v\n", err)
		return
	}
}
